package org.tsp.android.GUI_Menus;

import java.io.IOException;
import java.io.InputStream;
import java.util.Currency;

import org.tsp.android.GUI_Menus.R;
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class GUI_MenusActivity extends Activity {
    /** Called when the activity is first created. */
	
	private Boolean text_bold = false;
	private Boolean text_italic = false;
	
	private Handler mHandler = new Handler();
	
	private Boolean slideshow_started = false;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
    }
	
	@Override
	public void onResume()
	{
		super.onResume();

		if ( slideshow_started )
			mHandler.postDelayed(mUpdateTimeTask, 3000);
	}
	
	@Override 
	public void onPause()
	{
		super.onPause();
		
		mHandler.removeCallbacks(mUpdateTimeTask);
	}
	
	@Override
	public void onDestroy()
	{
		super.onDestroy();
		
	}
    
    public void loadImageClick(View v)
    {
    	loadImage("/sdcard/img.jpg");
    }
    
    private void loadImage(String img_name)
    {
    	Bitmap bmp = BitmapFactory.decodeFile(img_name);
    	
    	// To Complete
    	// Load the image in the view
    }
    
    public void startSlidesowClick(View v)
    {
    	slideshow_started = true;
    	mHandler.removeCallbacks(mUpdateTimeTask);
        mHandler.postDelayed(mUpdateTimeTask, 3000);
        
        startActivity(new Intent(GUI_MenusActivity.this , Activity_2.class));
    }
    
    private void loadImageFromStream(InputStream img_stream)
    {
    	final Bitmap bmp = BitmapFactory.decodeStream(img_stream);
		this.runOnUiThread(new Runnable(){

			public void run() {
				// To complete
				// Set the image on the ImageView
			}
			
		});
    }
    
    private void loadImageAssets(String image)
    {
    	// To complete
    	// Use the AssetManager to open the InputStream for 
    	// the requested image and load it in the view
    }
    
    private Runnable mUpdateTimeTask = new Runnable() {
    	   public void run() {
    		   mHandler.postDelayed(mUpdateTimeTask, 3000);
//    		   try {
    			   // To complete
    			   // Use Asset Manager to get the list of files
    			   // Change the image at each run of this function 
					
//    		   } catch (IOException e) {
//    			   e.printStackTrace();
//    		   }
    	   }
    	};
    
       
    @Override 
    public boolean onCreateOptionsMenu(Menu menu)
    {
    	MenuInflater inf = getMenuInflater();
    	inf.inflate(R.menu.main_menu, menu);
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
    	switch (item.getItemId())
    	{
    		case R.id.menu_exit:
    			this.finish();
    			return true;

    			// To Complete
    			// Change the checked state of the menu item
    			// and update the text style

    		default: 
    			return super.onOptionsItemSelected(item);
    	}
    }

}